package cn.wpp;


/*
 * 同步线程的两种方式
 * 第一种是实现
 *
 *
 *
 * */
class test implements Runnable {
    private int taket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (taket > 0) {
                    System.out.println(Thread.currentThread().getName() + ":" + taket);
                }
                taket--;

            }
        }
    }
}


public class snychronizedThread {
    public static void main(String args[]) {
        test test = new test();
        Thread thread1 = new Thread(test);
        Thread thread2 = new Thread(test);
        Thread thread3 = new Thread(test);

        thread1.start();
        thread2.start();
        thread3.start();
    }

}
